package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("user")
public class UserController  {

   @Reference
    private UserService userService;


    @PostMapping("/addUser")
    public  boolean addUser( User user){
      return   userService.add(user);
    }



    @DeleteMapping("/{id}")
    public  boolean deleteUser(Integer id){
        return  userService.delete(id);
    }


    @PutMapping("/updateUser")
    public  boolean updateUser( User user){
        System.out.println(user);
        return  userService.update(user);
    }



    @GetMapping("findUserById/{id}")
    public User findUserById(@PathVariable Integer id){
        System.out.println(11);
        return  userService.findById(id);

    }



    @PutMapping("/{page}/{size}")
    public PageInfo findAllUser(@PathVariable int page,@PathVariable int size){
        return  userService.findAll(page,size);
    }
}
